import React, { Component } from "react";

export default class Footer extends Component {
  render() {
    let { todoList, clearAll, chooseAll } = this.props;
    let total = todoList.length;
    let completed = todoList.reduce((pre, cur) => pre + cur.done, 0);
    let isAll = completed === total;
    return (
      <div className="todo-footer">
        <label>
          <input
            type="checkbox"
            checked={isAll}
            onChange={() => chooseAll(isAll)}
          />
        </label>
        <span>
          <span>已完成{completed}</span> / 全部{total}
        </span>
        <button className="btn btn-danger" onClick={clearAll}>
          清除已完成任务
        </button>
      </div>
    );
  }
}
